<link href="${rc.getContextPath()}/manage/css/dwzCustomCss/dwz.custom.css?v=${ver}" rel="stylesheet" type="text/css">
<style>
.d span.error {
position: absolute !important;
left: 260px;
}
</style>
<div class="pageContent">
    <form id="taskForm" method="post" action="${rc.getContextPath()}/manage/maintainTask/saveMaintainTask" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
        <div class="pageFormContent">
         <input type="hidden" id="failureCause" name="failureCause" >
          <input type="hidden" id="isSave" name="isSave" >
         <input type="hidden" id="part" name="part" >
            <input type="hidden" name="navTabId" value="${navTabId!''}"> <input type="hidden" name="id" value="<#if (task.taskCode)??>${task.taskCode!''}</#if>">
            <fieldset>
                <dl>
                    <dt><@label key="taskCode.C,colon">任务编号：</@label></dt>
                    <dd>
                        <input name="taskCode" value="<#if (task.taskCode)??>${task.taskCode!''}</#if>" size="32" type="text" maxlength="20" readonly="readonly" />
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="statusECode.C,colon">任务状态：</@label></dt>
                    <dd>
                        <select disabled name="statusECode"> <#list status as types>
                            <option value="${types.eCode}"<#if task.statusECode?? && task.statusECode == types.eCode> selected="selected"</#if>>${types.eCodeText}</option> </#list>
                        </select>
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="equipmentCode.C,colon">设备编号：</@label></dt>
                    <dd>
                        <input readonly class="required" id="equipmentLookup.equipmentCode" name="equipmentCode" type="text" value="<#if (task.equipmentCode)??>${task.equipmentCode!''}</#if>" />
                    </dd>
                </dl>
                <dl>
                    <dt><@label key='equipmentText.C,colon'>设备描述：</@label></dt>
                    <dd>
                        <input id="equipmentLookup.equipmentText" readonly size="22" type="text" maxlength="60" name="equipmentText" value="<#if (task.equipmentText)??>${task.equipmentText!''}</#if>" />
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="plannedMaintainDate.C,colon">计划维护日期：</@label></dt>
                    <dd>
                        <input type="text" value="<#if (task.plannedMaintainDate)??>${task.plannedMaintainDate?string("yyyy-MM-dd")}</#if>" class="required" readonly="readonly" name="plannedMaintainDate" dateFmt="yyyy-MM-dd" />
                    </dd>
                </dl>
                <dl style="height: 70px; width: 600px">
                    <dt><@label key="memo.C,colon">备注：</@label></dt>
                    <dd>
                        <textarea readonly style="width: 435px; height: 68px;" maxlength="200" name="memo" cols="45" rows="4"><#if (task.memo)??>${task.memo!''}</#if></textarea>
                    </dd>
                </dl>
                <dl>
                    <dt>&nbsp;</dt>
                    <dd>
                        <label><input disabled type="checkbox" name="unPlannedFlag" value="1"<#if (task.unPlannedFlag)?? && (task.unPlannedFlag == 1)> checked="true"</#if>><@label key="unPlannedFlag.C">手工创建标识</@label></label>
                    </dd>
                </dl>
                <dl style="width: 100%;height: auto;clear: both;">
                    <dd>
                        <div class="tabs" currentIndex="0" eventType="click" style="width: 600px;">
                            <div class="tabsHeader">
                                <div class="tabsHeaderContent">
                                    <ul>
                                        <li><a href="javascript:;"><span><@label key="maintainDetail.C">维护记录</@label></span> </a>
                                        </li>
                                        <li><a href="javascript:;"><span><@label key="failureCause.C">故障原因</@label></span> </a>
                                        </li>
                                        <li><a href="javascript:;"><span><@label key="maintainPart.C">更换备件记录</@label></span> </a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                            <div class="tabsContent">
                                <div>
                                    
                                    <dl style="height: 70px; width: 590px">
                                        <dt><@label key="maintainMemo.C,colon">维护内容：</@label></dt>
                                        <dd>
                                            <textarea class="required" style="width: 435px; height: 68px;" maxlength="200" name="maintainMemo" cols="45" rows="4"><#if (task.maintainMemo)??>${task.maintainMemo!''}</#if></textarea>
                                        </dd>
                                    </dl>
                                    <dl style="height: 70px; width: 590px">
                                        <dt><@label key="maintainResult.C,colon">维护结果：</@label></dt>
                                        <dd>
                                            <textarea class="required" style="width: 435px; height: 68px;" maxlength="200" name="maintainResult" cols="45" rows="4"><#if (task.maintainResult)??>${task.maintainResult!''}</#if></textarea>
                                        </dd>
                                    </dl>
                                    <dl style="width: 280px">
                                        <dt><@label key='maintainUser.C,colon'>维护人：</@label></dt>
                                        <dd>
                                            <input class="required" size="22" type="text" maxlength="40" name="maintainUser" value="<#if (task.maintainUser)??>${task.maintainUser!''}</#if>" />
                                        </dd>
                                    </dl>
                                    <dl style="width: 280px"></dl>
                                    <dl style="width: 280px" class="d">
                                        <dt><@label key="maintainStartDateTime.C,colon">维护开始时间：</@label></dt>
                                        <dd>
                                            <input type="text" class="required date" datefmt="yyyy-MM-dd HH:mm:ss" readonly="readonly" name="maintainStartDateTime"  value="<#if (task.maintainStartDateTime)??>${task.maintainStartDateTime?string("yyyy-MM-dd HH:mm:ss")}</#if>"/> <a class="inputDateButton" href="javascript:;"><@label key="select.B">选择</@label></a>
                                        </dd>
                                    </dl>
                                    <dl style="width: 280px" class="d">
                                        <dt><@label key="maintainEndDateTime.C,colon">维护结束时间：</@label></dt>
                                        <dd>
                                            <input type="text" class="required date" datefmt="yyyy-MM-dd HH:mm:ss" readonly="readonly" name="maintainEndDateTime" value="<#if (task.maintainEndDateTime)??>${task.maintainEndDateTime?string("yyyy-MM-dd HH:mm:ss")}</#if>"/> <a class="inputDateButton" href="javascript:;"><@label key="select.B">选择</@label></a>
                                        </dd>
                                    </dl>
                    
                                </div>
                                <div>
                                    <div class="pBar">
                                        <ul class="toolBar">
                                            <input id="failureid" name="failureLookup.failureCauseCode" type="hidden" type="text" />
                                            <input id="failurename" name="failureLookup.failureCauseText" type="hidden" type="text" />
                                            <li><a class="add" width="640" height="500" href="${rc.getContextPath()}/manage/failureCause/failureCauseLookup?navTabId=${navTabId!''}" lookupGroup="failureLookup" callback="maintainTaskJs._failure_callback"><span><@label key="add.B">新增</@label></span> </a>
                                            </li>
                                        </ul>
                                    </div>
                                    <table id="failureCauseTable" class="table border" style="width: 100%;" layoutH="384">
                                        <thead>
                                            <tr>
                                                <th width="115px"><@label key="failureCauseCode.C">故障原因编号</@label></th>
                                                <th width="233px"><@label key="failureCauseText.C">故障原因描述</@label></th>
                                                <th width="115px"><@label key="opera.C">操作</@label></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <#if causes??><#if (causes?size>0)> <#list causes as cause>
                                            <tr id="f_${cause.failureCauseCode!''}">
                                                <td width="115px">${cause.failureCauseCode!''}</td>
                                                <td width="233px">${cause.failureCauseText!''}</td>
                                                <td width="115px"><a title="<@label key='delete.B'>删除</@label>" target='ajax' class='btnDel' onclick="maintainTaskJs._delFailure('${cause.failureCauseCode!''}');"><@label key='delete.B'>删除</@label></a></td>
                                            </tr>
                                            </#list> </#if> </#if>
                                        </tbody>
                                    </table>
                                </div>
                                <div>
                                    <div class="pBar">
                                        <ul class="toolBar">
                                            <li><a class="add" target="dialog" mask="true" width="450" height="280" rel="addProcessComponent" title="<@label key='add.B,component.C'>新增组件</@label>" href="${rc.getContextPath()}/manage/maintainTask/addPart"><span><@label key="add.B">新增</@label></span> </a></li>
                                        </ul>
                                    </div>
                                    <table id="partTable" class="table border" style="width: 100%;" layoutH="384">
                                        <thead>
                                            <tr>
                                                <th width="137px"><@label key="partCode.C">备件编号</@label></th>
                                                <th width="137px"><@label key="partText.C">备件描述</@label></th>
                                                <th width="137px"><@label key="quantity.C">数量</@label></th>
                                                <th width="67px"><@label key="opera.C">操作</@label></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                              <#if parts??><#if (parts?size>0)> <#list parts as part>
                                            <tr  id="part_${part.partCode!''}" name="part_${part.partCode!''}&${part.quantity!''}">
                                                <td width="137px">${part.partCode!''}</td>
                                                <td width="137px">${part.partText!''}</td>
                                                <td width="137px">${part.quantity!''}</td>
                                                <td width="67px"><a title="<@label key='delete.B'>删除</@label>" target='ajax' class='btnDel' onclick="maintainTaskJs._delPart('part_${part.partCode!''}');"><@label key='delete.B'>删除</@label></a></td>
                                            </tr>
                                            </#list> </#if> </#if>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <div class="tabsFooter">
                            </div>
                        </div>
                    </dd>
                </dl>
            </fieldset>
        </div>
        <div class="formBar">
            <ul>
                <li><div class="buttonActive">
                        <div class="buttonContent">
                            <button type="button" onclick="maintainTaskJs._temporarySave()"><@label key="save.B">保存</@label></button>
                        </div>
                    </div></li>
                            <li><div class="buttonActive">
                        <div class="buttonContent">
                            <button type="submit" onclick="maintainTaskJs._save()"><@label key="submit.B">提交</@label></button>
                        </div>
                    </div></li>
                <li>
                    <div class="buttonActiveGrey">
                        <div class="buttonContent">
                            <button type="button" class="close"><@label key="cancel.B">取消</@label></button>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </form>
</div>

<script type="text/javascript">
var maintainTaskJs = {
        _save:function()
        {
            var failureCause = "";
            var part = "";
            var failureCausetable = $("#failureCauseTable");
            var parttable = $("#partTable");
            failureCausetable.find("table tbody tr").each(function(i, n) {
                var obj = $(n)
                failureCause += obj.attr("id").replace("f_", "") + ",";
            });
            parttable.find("table tbody tr").each(function(i, n) {
                var obj = $(n)
                part += obj.attr("name").replace("part_", "") + ",";
            });
        
            if (failureCause.length > 1) {
                failureCause = failureCause.substring(0, failureCause.length - 1);
            }
            if (part.length > 1) {
                part = part.substring(0, part.length - 1);
            }
            $("#failureCause").val(failureCause);
            $("#part").val(part);
        },
        _temporarySave:function(){
            maintainTaskJs._save();
            $('#isSave').val('1');
            var form=$('#taskForm');
            $.ajax({
                type: 'POST',
                url:form.attr("action"),
                data:form.serializeArray(),
                dataType:"json",
                cache: false,
                success:dialogAjaxDone,
                error: DWZ.ajaxError
            });
        },
        _failure_callback:function(){
            var id = $("#failureid").val();
            var name = $("#failurename").val();
            var idArr = new Array();
            var nameArr = new Array();
            idArr = id.split(',');
            nameArr = name.split(',');
            var ht = "";
            for ( var i = 0; i < idArr.length; i++) {
                var failureid = idArr[i];
                var failurename = nameArr[i];
                var gridTheadTh = $("#failureCauseTable").find("table thead th");
                var tr = "<tr id='f_"+failureid+"'>";
                tr += "<td style='width:"+$(gridTheadTh[0]).width()+"px'><div>"+failureid+"</div></td>";
                tr += "<td style='width:"+$(gridTheadTh[1]).width()+"px'><div>"+failurename+"</div></td>";
                tr += "<td style='width:"+$(gridTheadTh[2]).width()+"px'><a title='<@label key='delete.B'>删除</@label>' target='ajax' class='btnDel' onclick='maintainTaskJs._delFailure(\""+failureid+"\");'><@label key='delete.B'>删除</@label></a></td>";
                tr += "</tr>";
                $("tr#f_"+failureid).remove();
                $("#failureCauseTable .gridTbody").find("table tbody").append(tr);
            }
        
        },
        _delFailure : function(_id){
            event.stopPropagation();
            if(_id){
                alertMsg.confirm("<@label key='delete_sure.D'>确定删除</@label>？",{
                    okCall:function(){
                            $("tr#f_"+_id).remove();
                            
                        }
                    });
            }
        },
        _addPart : function(data) {
            if(!data)
                return;
            var gridTheadTh = $("#partTable").find("table thead th");
            var _id = "part"+"_"+data.partCode;
            var _name="part"+"_"+data.partCode+"&"+data.quantity;
            var tr = "<tr id='"+_id+"'name='"+_name+"'>";
            tr += "<td style='width:"+$(gridTheadTh[0]).width()+"px'><div>"+data.partCode+"</div></td>";
            tr += "<td style='width:"+$(gridTheadTh[1]).width()+"px'><div>"+data.partText+"</div></td>";
            tr += "<td style='width:"+$(gridTheadTh[2]).width()+"px'><div>"+data.quantity+"</div></td>";
            tr += "<td style='width:"+$(gridTheadTh[3]).width()+"px'><a title='<@label key='delete.B'>删除</@label>' target='ajax' class='btnDel' onclick='maintainTaskJs._delPart(\""+_id+"\");'><@label key='delete.B'>删除</@label></a></td>";
            tr += "</tr>";
            $("tr#"+_id).remove();
            $("#partTable .gridTbody").find("table tbody").append(tr);
        },
        _delPart : function(_id){
            event.stopPropagation();
            if(_id){
                alertMsg.confirm("<@label key='delete_sure.D'>确定删除</@label>？",{
                    okCall:function(){
                            $("tr#"+_id).remove();
                        }
                });
            }
        }
}

</script>